import 'dotenv/config'; // 加载环境变量
import "reflect-metadata";
import {createConnection} from 'typeorm';
import express, {Express} from 'express';
import bodyParser from 'body-parser';

import userRouter from './controller/user';
import taskRouter from './controller/task';
import syncRouter from './controller/sync';

const cors = require('cors');

const app: Express = express();

app.use(bodyParser.json());

// ...其他中间件
app.use(cors());

// 添加路由
app.use('/api/users', userRouter);
app.use('/api/tasks', taskRouter);
app.use('/api/sync', syncRouter);

// 定义根路由
app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(3001, () => {
    console.log('Server is running on port 3001');
});


createConnection().then(() => {
    console.log('Connected to database');
});
